<?php

use yii\helpers\Html;
use kartik\select2\Select2;
use app\modules\Order\models\Leader;

$this->title = $cruise->name;

 

?>
<?= yii\web\View::registerCssFile("/css/magic-check.css",['depends' => 'app\assets\AppAsset']) ?>
<style type="text/css">
	.order-view font {color:#9E9A9A;margin-right:10px;}
	.team{border: 1px solid #ddd;border-radius: 4px;padding-left: 15px;margin-right: 15px;height: 130px;margin-top: 10px;}
	.team .team-t{padding: 15px;height: 70px;background: #dff0d8;margin-top: 15px;line-height: 15px;text-align: center;}
	.team .team-p{margin-top: 15px;}
	.team .team-b{height: 40px;line-height: 50px;text-align: center;}
	.magic-radio + label, .magic-checkbox + label{display: inline;}

	.download{border: 1px solid #ddd;padding: 15px;border-radius: 3px;}
	.list-group-item{line-height: 30px;}

</style>

<div class="order-view">
    <h2 class="page-header">
    	 <small><?=yii::$app->params['template'][$template_id]?></small>
    	 &nbsp;&nbsp;<small>[ <?= Html::encode($this->title) ?> ]</small>
    </h2>
	

	<input type="hidden" name="template_id" id="template_id" value="<?=$template_id?>">
	<input type="hidden" name="cruise_id" id="cruise_id" value="<?=$cruise->id?>">
	<input type="hidden" value="<?php echo Yii::$app->getRequest()->getCsrfToken(); ?>" name="_csrf" id="_csrf" />

	<div class="row" style="padding: 15px;">
    	<?php if(!empty($group_arr)) { ?>
    		<?php foreach ($group_arr as  $v){?>
   				<div class="col-md-1 team">
   					 <div class="team-t">
   					 		<?=$v?>
   					 </div>
   					
   					 <div class="team-b">
   					 	<input class="magic-checkbox group_class" type="checkbox" name="layout" id="assign_<?=$v?>" value="<?=$v?>" data-leader="<?=$v?>">
   					 	<label for="assign_<?= $v?>"></label>
   					 </div>
   				</div>
    		<?php }?>


    	<?php }?>

				
	</div>

	

	<div class="row" style="text-align: center;margin-top: 30px;">

		<button type="button" class="btn btn-warning" id="create_name">生成团队名单</button>

		<input class="magic-checkbox room_all" type="checkbox" id="room_all"  ><label for="room_all"  style="display:inline;margin-left: 30px;" title="选择全部团号">选择全部团号</label>
	</div>

	<div class="row col-md-6" id="file" style="padding-top:30px;">
			
			
	</div>

	

</div>


<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">
	 
	 $(".room_all").click(function(){
	    var checked = $(this).is(':checked');
	    
	    if(checked){
	        $(".group_class").each(function(){

	            $(this).prop("checked",true);  // attr 第三次会失败
	        });
	    }else{
	        $(".group_class").each(function(){
	        	
	            $(this).prop("checked", false);
	        });
	    }
	    
	});


	$("#create_name").click(function(){

		var template_id = $("#template_id").val();

		var cruise_id = $("#cruise_id").val();

		var _csrf = $("#_csrf").val();

		var assign_arr = [];

		$('input:checkbox[name=layout]:checked').each(function(i){
		     var assign_id = $(this).val();
		     var lead_id = $(this).attr("data-leader");
		     assign_arr[i] = {'assign_id':assign_id,'lead_id':lead_id};
      	});

      	if(assign_arr.length === 0){
      		alert("没有选择团队!");
      		return false;
      	}

      	$.ajax({
		   type: "POST",
		   async:false, 
		   url: "/cruise/customer/excel",
		   data: {"_csrf":_csrf,"template_id":template_id,"cruise_id":cruise_id,"assign_arr":assign_arr},
		   success: function(msg){
		   	  
		       var res = $.parseJSON(msg);
		       if(res.status == 0){
		       	   alert("生成团队名单失败");
		       	   return false;
		       }else if(res.status == 1){

		       	var href = "/cruise/customer/download-file?name="+res.data.down_name+"&url="+res.data.down_url;
		       	window.location.href = href;
					
		       }

		   }
		});

	});

	

</script>
<?php app\components\JsBlock::end() ?>
